<template>
	<view class="container">
		<view class="main">
			<view class="title">
				{{itemData.itemName }}
			</view>
			<view class="online_box" v-if="userType == 1">
				<view class="small_title">
					审批业务
				</view>
				<view class="online_info">
					<view class="">
						企业名称：<text>{{userInfo.unitName}}</text>
					</view>
				</view>
				<view class="online_info">
					<view class="">
						统一社会信用代码：<text>{{userInfo.unitNumber}}</text>
					</view>
				</view>
				<view class="online_info">
					<view class="">
						机构类型：<text>{{jglx}}</text>
					</view>
				</view>
				<view class="online_info">
					<view class="">
						法定代表：<text>{{user.name}}</text>
					</view>
				</view>
				<view class="online_info">
					<view class="">
						证件类型：<text>身份证</text>
					</view>
					<view class="">
						证件号码：<text>{{user.idcard}}</text>
					</view>
				</view>
				<view class="online_info">
					<view class="">
						联系人：<text>{{userInfo.unitLinkMan}}</text>
					</view>
					<view class="">
						联系电话：<text>{{userInfo.unitLinkPhone}}</text>
					</view>
				</view>
			</view>
			<view class="online_box" v-if="userType == 0">
				<!-- 个人 -->
				<view class="small_title">
					审批业务
				</view>
				<view class="online_info">
					<view class="">
						姓名：<text>{{user.name}}</text>
					</view>
					<view class="">
						联系电话：<text>{{user.phone}}</text>
					</view>
				</view>
				<view class="online_info">
					<view class="">
						证件类型：<text>身份证</text>
					</view>
					<view class="">
						证件号码：<text>{{user.idcard}}</text>
					</view>
				</view>
			</view>

			<view class="online_box" v-if="userType == 1">
				<!-- 法人 -->
				<view class="small_title">
					申报信息
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						经办人姓名：
					</view>
					<u-input placeholder='请输入' v-model="formData.handleName" type="text" :border="border"
						:input-align="inputAlign" />
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						经办人联系方式：
					</view>
					<u-input placeholder='请输入' v-model="formData.handlePhone" type="number" :border="border"
						:input-align="inputAlign" />
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						经办人身份证：
					</view>
					<u-input placeholder='请输入' v-model="formData.handleIdcard" type="text" :border="border"
						:input-align="inputAlign" />
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						经办人地址：
					</view>
					<u-input placeholder='请输入地址' v-model="formData.handleAddress" type="text" :border="border"
						:input-align="inputAlign" />
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						登记机关：
					</view>
					<u-input placeholder='营业执照登记机关' v-model="formData.department" type="text" :border="border"
						:input-align="inputAlign" />
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						注册资本（万元）：
					</view>
					<u-input placeholder='所填内容需与营业执照一致' v-model="formData.money" type="number" :border="border"
						:input-align="inputAlign" />
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						登记注册日期：
					</view>
					<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
						<view class="uni-input">{{date}}</view>
					</picker>
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						注册地址：
					</view>
					<u-input placeholder='所填内容需与营业执照一致' v-model="formData.place" type="text" :border="border"
						:input-align="inputAlign" />
				</view>
				<view class="fill_list">
					<view class="">
						项目名称：
					</view>
					<u-input placeholder='请输入' v-model="itemData.itemName" type="text" :border="border"
						:input-align="inputAlign" disabled />
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						企业所在地：
					</view>
					<view class="selectBox">
						<u-input placeholder='请选择' v-model="formData.location" type="text" :border="border"
							:input-align="inputAlign" disabled @click="select(1)" />
						<u-select value-name="code" label-name="name" child-name="cityList" v-model="show"
							mode="mutil-column-auto" :list="Resgion" @confirm="confirm">
						</u-select>
					</view>
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						企业详细地址：
					</view>
					<u-input placeholder='请输入企业地址' v-model="formData.address" type="text" :border="border"
						:input-align="inputAlign" />
				</view>
				<view class="fill_list">
					<view class="">
						备注：
					</view>
					<u-input placeholder='请输入(500字内)' maxlength="500" v-model="formData.remark" type="textarea"
						height="70" :border="border" :input-align="inputAlign" />
				</view>
			</view>

			<view class="online_box" v-if="userType == 0">
				<!-- 法人 -->
				<view class="small_title">
					申报信息
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						性别：
					</view>
					<view class="selectBox">
						<u-input placeholder='请选择' v-model="formData.sexName" type="text" :border="border"
							:input-align="inputAlign" disabled @click="select(2)" />
						<u-select v-model="sexShow" :list="sexList" @confirm="sexConfirm">
						</u-select>
					</view>
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						民族：
					</view>
					<view class="selectBox">
						<u-input placeholder='请输入名族(汉族)' v-model="formData.nation" type="text" :border="border"
							:input-align="inputAlign" />
					</view>
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						出生日期：
					</view>
					<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
						<view class="uni-input">{{date}}</view>
					</picker>
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						联系地址：
					</view>
					<u-input placeholder='请输入联系地址' v-model="formData.address" type="text" :border="border"
						:input-align="inputAlign" />
				</view>
				<view class="fill_list">
					<view class="">
						<text>*</text>
						户籍所在地：
					</view>
					<view class="selectBox">
						<u-input placeholder='请选择' v-model="formData.location" type="text" :border="border"
							:input-align="inputAlign" disabled @click="select(1)" />
						<u-select value-name="code" label-name="name" child-name="cityList" v-model="show"
							mode="mutil-column-auto" :list="Resgion" @confirm="confirm">
						</u-select>
					</view>
				</view>
			</view>

		</view>
		<view class="footer">
			<!-- $gopage('/pages/matter/uploadFile') -->
			<view class="sureBtn" @click="submit">
				下一步，上传材料
			</view>
		</view>



	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				userInfo: {

				},
				itemCode: '',
				itemData: {},
				data7: [],
				jglx: '',
				companyName: '',
				border: false,
				inputAlign: 'right',
				show: false,
				date: currentDate,
				userType: uni.getStorageSync("userType"),
				user: {},
				Resgion: [],
				formData: {
					handleName: '',
					handlePhone: '',
					handleIdcard: '',
					handleAddress: '',
					department: '',
					money: '',
					place: '',
					address: '',
					remark: '',
					location: '',
					cityCode: '',
					sex: '',
					sexName: '',
					nation: ''
				},
				sexList: [{
						value: 0,
						label: "男",
					},
					{
						value: 1,
						label: "女",
					},
				],
				sexShow: false
			}
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		onLoad(option) {
			this.itemCode = option.itemCode;
			this.selectItemDetail();
			this.getUserInfo();
			this.getResgion();
		},
		methods: {
			select(type) {
				if (type == 1) {
					this.show = true;
				}
				if (type == 2) {
					this.sexShow = true;
				}
			},
			submit() {
				let that = this;
				if (this.userType == 1) {
					if (/^\s*$/.test(this.formData.handleName)) {
						uni.showToast({
							title: '请输入经办人姓名',
							icon: 'none'
						});
						return false
					}

					if (!/^(?:(?:\+|00)86)?1[3-9]\d{9}$/.test(this.formData.handlePhone)) {
						uni.showToast({
							title: '请输入正确经办人联系方式',
							icon: 'none'
						});
						return false
					}
					if (!/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/.test(this
							.formData.handleIdcard)) {
						uni.showToast({
							title: '请输入正确经办人身份证',
							icon: 'none'
						});
						return false
					}
					if (/^\s*$/.test(this.formData.handleAddress)) {
						uni.showToast({
							title: '请输入经办人地址',
							icon: 'none'
						});
						return false
					}
					if (/^\s*$/.test(this.formData.department)) {
						uni.showToast({
							title: '请输入登记机关',
							icon: 'none'
						});
						return false
					}
					if (/^\s*$/.test(this.formData.money)) {
						uni.showToast({
							title: '请输入注册资本',
							icon: 'none'
						});
						return false
					}
					if (/^\s*$/.test(this.formData.place)) {
						uni.showToast({
							title: '请输入注册地址',
							icon: 'none'
						});
						return false
					}
					if (/^\s*$/.test(this.formData.address)) {
						uni.showToast({
							title: '请输入企业详细地址',
							icon: 'none'
						});
						return false
					}
					if (/^\s*$/.test(this.formData.cityCode)) {
						uni.showToast({
							title: '请选择企业所在地',
							icon: 'none'
						});
						return false
					}
					var data = {

						agentName: that.userInfo.unitName, // 企业名称
						agentCode: '360728-000202042000',
						socialCreditCode: that.userInfo.unitNumber, // 统一社会信用代码
						organType: that.jglx, // 机构类型
						legalPerson: that.userInfo.unitLinkMan, // 法定代表
						cardType: '身份证', // 证件类型
						cardNo: that.user.idcard, // 身份证号
						linkMan: that.userInfo.unitLinkMan, // 联系人、
						linkPhone: that.userInfo.phone, // 联系号码
						agents1: that.formData.handleName, // 经办人姓名
						address1: that.formData.handlePhone, // 经办人联系方式
						idCard: that.formData.handleIdcard, // 经办人身份证
						addr: that.formData.handleAddress, // 经办人地址
						registerUnit: that.formData.department, // 登记机关
						capital: that.formData.money, // 注册资金
						registeredDate: that.date, // 注册日期
						registerAddr: that.formData.place, // 注册地址
						applyName: that.itemData.itemName, // 项目名称
						regionCode: that.formData.cityCode, // 地区编码
						frName: that.user.name,
						remark: that.formData.remark, // 备注
						detailAddr: that.formData.address, // 企业得详细地址
						itemCode: that.itemData.itemCode,
						startUserId: that.user.id,
						startUserName: that.userInfo.unitName,
						dataFrom: 1,
						isSubmit: "1",
						startUserType: this.userType,
						code: '123456789',
						sex: ''
					};
				}

				if (this.userType == 0) {
					if (/^\s*$/.test(this.formData.sex)) {
						uni.showToast({
							title: '请选择性别',
							icon: 'none'
						});
						return false
					}
					if (/^\s*$/.test(this.formData.nation)) {
						uni.showToast({
							title: '请输入民族',
							icon: 'none'
						});
						return false
					}
					if (/^\s*$/.test(this.formData.address)) {
						uni.showToast({
							title: '请输入联系地址',
							icon: 'none'
						});
						return false
					}
					if (/^\s*$/.test(this.formData.cityCode)) {
						uni.showToast({
							title: '请选择户籍所在地',
							icon: 'none'
						});
						return false
					}

					var data = {
						cardType: '身份证', // 证件类型
						userName: that.user.name, // 联系人、
						linkPhone: that.user.phone, // 联系号码
						birthday: that.date, // 出生日期
						regionCode: that.formData.cityCode, // 地区编码
						nation: that.formData.nation,
						itemCode: that.itemData.itemCode,
						startUserId: that.user.id,
						startUserName: that.user.name,
						startUserType: that.userType,
						sex: that.formData.sexName,
						userType: that.userType,
						detailAddr: that.formData.address,
						idCard: that.user.idcard
					};
				}

				uni.setStorageSync('matterData', JSON.stringify(data));
				uni.redirectTo({
					url: '/pages/matter/uploadFile'
				})
			},
			getResgion() {
				this.$ajax({
					url: '/api/wwwNews/getResgion2',
					method: 'GET',
				}).then(res => {
					if (res.code == 200) {
						this.Resgion = res.data;
						console.log(this.Resgion)
					}
				})
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			confirm(e) {
				this.formData.location = '';
				e.forEach(item => {
					this.formData.location += item.label
				})
				this.formData.cityCode = e[e.length - 1].value;
			},
			sexConfirm(e) {
				this.formData.sexName = e[0].label;
				this.formData.sex = e[0].value;
				console.log(e)
			},
			bindDateChange(e) {
				this.date = e.target.value
			},
			selectItemDetail() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				this.$ajax({
					url: '/api/wwwBiz/selectItemDetail',
					method: 'POST',
					data: {
						itemCode: this.itemCode,
						userType: uni.getStorageSync('userType')
					}
				}).then(res => {
					if (res.code == 200) {
						this.itemData = res.data.data1;
						this.data7 = res.data.data7;
					}
				}).finally(() => {
					uni.hideLoading();
				})
			},
			getUserInfo() {
				var that = this
				uni.showLoading({
					title: '查询中...',
					mask: true
				});
				this.$ajax({
					url: '/api/wwwNews/getUserInfo',
					method: 'POST',
					needAuth: true,
					params: {
						userType: this.userType,
						accessToken: uni.getStorageSync('access_token')
					},
				}).then(res => {
					if (res.code == 200) {
						this.user = res.data.user;
						if (this.userType == 1) {
							this.userInfo = res.data.legalInfo;
							if (that.userInfo.orgId.substring(1, 1) == '1' && (that.userInfo.orgId.substring(0,
										1) ==
									'1')) {
								that.jglx = '机关编制机关';
							};
							if (that.userInfo.orgId.substring(1, 1) == '2' && (that.userInfo.orgId.substring(0,
										1) ==
									'1')) {
								that.jglx = '机关编制事业';
							};
							if (that.userInfo.orgId.substring(1, 1) == '3' && (that.userInfo.orgId.substring(0,
										1) ==
									'1')) {
								that.jglx = '机关编制群众团体';
							};
							if (that.userInfo.orgId.substring(1, 1) == '9' && (that.userInfo.orgId.substring(0,
										1) ==
									'1')) {
								that.jglx = '机关编制其他';
							};
							if (that.userInfo.orgId.substring(1, 1) == '1' && (that.userInfo.orgId.substring(0,
										1) ==
									'5')) {
								that.jglx = '民政社会团体';
							};
							if (that.userInfo.orgId.substring(1, 1) == '2' && (that.userInfo.orgId.substring(0,
										1) ==
									'5')) {
								that.jglx = '民政民办非企业单位';
							};
							if (that.userInfo.orgId.substr(1, 1) == '3' && (that.userInfo.orgId.substr(0, 1) ==
									'5')) {
								that.jglx = '民政基金会';
							};
							if (that.userInfo.orgId.substr(1, 1) == '9' && (that.userInfo.orgId.substr(0, 1) ==
									'5')) {
								that.jglx = '民政其他';
							};
							if (that.userInfo.orgId.substr(1, 1) == '1' && (that.userInfo.orgId.substr(0, 1) ==
									'9')) {
								that.jglx = '工商企业';
							};
							if (that.userInfo.orgId.substr(1, 1) == '2' && (that.userInfo.orgId.substr(0, 1) ==
									'9')) {
								that.jglx = '工商个体工商户';
							};
							if (that.userInfo.orgId.substr(1, 1) == '3' && (that.userInfo.orgId.substr(0, 1) ==
									'9')) {
								that.jglx = '工商农民专业合作社';
							};
							if (that.userInfo.orgId.substr(1, 1) == '9' && (that.userInfo.orgId.substr(0, 1) ==
									'9')) {
								that.jglx = '工商其他';
							};
						} else {
							this.userInfo = res.data.userInfo;
						}


					}
				}).finally(() => {
					uni.hideLoading();
				})
			},
		}
	}
</script>

<style scoped lang="less">
	/deep/.u-input__right-icon {
		display: flex;
		align-items: center;
	}

	.container {
		position: fixed;
		top: 0;
		bottom: 0;
		right: 0;
		left: 0;
		display: flex;
		justify-content: space-between;
		flex-direction: column;
	}

	.main {
		padding: 88rpx 30rpx 30rpx;
		flex: 1;
		overflow-y: auto;
	}

	.footer {
		height: 98rpx;
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 32rpx;

		.sureBtn {
			flex: 1;
			height: 100%;
			background-color: #5b96ff;
			border-top: 1rpx solid #5b96ff;
			color: #fff;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}

	.title {
		padding-left: 20rpx;
		margin-top: 40rpx;
		font-size: 44rpx;
		color: #333;
		font-weight: bolder;
	}



	.flex {
		display: flex;
		justify-content: space-between;
	}

	.flex_1 {
		flex: 1;
	}

	.online_box {
		margin-top: 40rpx;
		margin-left: 20rpx;
	}

	.small_title {
		font-size: 36rpx;
		position: relative;
		padding-left: 20rpx;

		&::after {
			position: absolute;
			top: 50%;
			left: 0;
			width: 6rpx;
			content: '';
			height: 75%;
			transform: translateY(-50%);
			background-color: #5b96ff;
		}
	}

	.online_info {
		font-size: 28rpx;
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		color: #999;

		>view {
			margin-top: 30rpx;

			&:nth-child(1) {
				margin-right: 30rpx;
			}

			text {
				color: #333;
			}
		}

	}

	.fill_list {
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 28rpx;
		color: #333;
		min-height: 104rpx;
		border-bottom: 1rpx solid #f1f1f1;

		>view {
			display: flex;
			align-items: center;

			&:nth-child(1) {
				font-size: 28rpx;
				height: 100%;

				text {
					margin-top: 4rpx;
					font-size: 26rpx;
					color: red;
					line-height: 26rpx;
					margin-right: 4rpx;
				}
			}
		}

	}

	.selectBox {
		flex: 1;
		height: 100%;
	}
</style>
